﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication3
{
    public partial class CustomerSearch : Form
    {
          private String connString = Program.ConnStr;
        
        public CustomerSearch()
        {
            InitializeComponent();
            showdata12();
        }




        public void showdata12()
        {
            try
            {
                String query = "Select * from customermastertable ";
                OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
                DataSet ds = new DataSet();
                dAdapter.Fill(ds, "tblcustdataview");
                tblcustomerdataview.DataSource = ds.Tables["tblcustdataview"].DefaultView;

            }
            catch (Exception exp)
            {
                MessageBox.Show("The application had met with some errors please restart  the application :\n error:closer MSAccess files");
                Console.WriteLine("Error", exp);
            }


        }

        private void btnsearch_Click(object sender, EventArgs e)
        {


            if (txtcustname.Text.Trim() != "")
            {
                try
                {


                    String query = "Select * from customermastertable where (companyname='" + txtcustname.Text + "')";
                    OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);


                    DataSet ds = new DataSet();
                    dAdapter.Fill(ds, "tbluserdataview");
                    tblcustomerdataview.DataSource = ds.Tables["tbluserdataview"].DefaultView;

                    tblcustomerdataview.AutoSizeColumnsMode =
            DataGridViewAutoSizeColumnsMode.Fill;
                }
                catch (Exception exp)
                {
                    MessageBox.Show("The application had met with some errors please restart  the application :\n error:closer MSAccess files");
                    Console.WriteLine(exp);
                }
            }

            else
            {

                MessageBox.Show("Enter the Customer Name");
            
            }



        }

        private void tblcustomerdataview_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (tblcustomerdataview.SelectedRows.Count == 0)
            {
                
            }
            else
            {
                int rowno = tblcustomerdataview.CurrentCellAddress.Y;
                int  userpk =int.Parse( tblcustomerdataview.Rows[rowno].Cells[0].Value.ToString());


                button1_Click(this, new EventArgs());

            }
        }

      

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            CustomerDataBean custdatabean = new CustomerDataBean();

            int rowno = tblcustomerdataview.CurrentCellAddress.Y;
            custdatabean.Customerpk = int.Parse(tblcustomerdataview.Rows[rowno].Cells[0].Value.ToString());
            custdatabean.Companyname = tblcustomerdataview.Rows[rowno].Cells[1].Value.ToString();
            custdatabean.Custcode = tblcustomerdataview.Rows[rowno].Cells[2].Value.ToString();
            custdatabean.Location = tblcustomerdataview.Rows[rowno].Cells[3].Value.ToString();
            custdatabean.Adress = tblcustomerdataview.Rows[rowno].Cells[4].Value.ToString();
            custdatabean.Contactperson = tblcustomerdataview.Rows[rowno].Cells[5].Value.ToString();
            custdatabean.Contactno = tblcustomerdataview.Rows[rowno].Cells[6].Value.ToString();
            custdatabean.Emailid = tblcustomerdataview.Rows[rowno].Cells[7].Value.ToString();
            custdatabean.Other = tblcustomerdataview.Rows[rowno].Cells[8].Value.ToString();

            NewJobCode newjobcode = new NewJobCode(custdatabean.Companyname, custdatabean.Custcode);
            this.Close();
            newjobcode.Show();
            

            
           
        }

        string _company;
        string _custcode;
        int _custpk;

        public int Custpk
        {
            get { return _custpk; }
            set { _custpk = value; }
        }
        public string CustomerCompany { get{
            return _company;
        }
            set {_company=value; }
        }

        public string CustomerCode
        {
            get
            {
                return _custcode;
            }
            set { _custcode = value; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void tblcustomerdataview_SelectionChanged(object sender, EventArgs e)
        {
            if (tblcustomerdataview.SelectedRows.Count > 0)
            {
                int rowno = tblcustomerdataview.CurrentCellAddress.Y;
               
                _custcode = tblcustomerdataview.SelectedRows[0].Cells[2].Value.ToString(); ;
                _company = tblcustomerdataview.SelectedRows[0].Cells[1].Value.ToString(); ;
                _custpk = int.Parse(tblcustomerdataview.Rows[rowno].Cells[0].Value.ToString()); ;
               
            }
          
        }

        private void button2_Click(object sendnder, EventArgs e)
        {
            Close();
        }
       

        






























    }
}
